<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="com.java.service.*,java.util.*,com.java.model.UserSession,com.java.util.*"%>
<jsp:include page="common/header.jsp"></jsp:include>
<%
	String statistics_type 	= CmmUtil.nvl(request.getParameter("statistics_type"),"day");
	String statistics_url 	= CmmUtil.nvl(request.getParameter("statistics_url"),"com0301l_p02");
	
	UserSession usersession = (UserSession)session.getAttribute("user");
	String ent_id 			= (String)session.getAttribute("ent_id");
	
	String connGroup 	= "";
	String user_id 		= "";

	if(usersession!=null){
		connGroup 	= CmmUtil.nvl(usersession.getConnGroup(),"0");
		user_id 	= CmmUtil.nvl(usersession.getUser_id(),"");
	}
	
	String present_Year = String.valueOf(GregorianCalendar.getInstance().get(Calendar.YEAR));
	//GregorianCalendar에서 1월 return 값이 0이므로 Month에는  1을 더해주어야 함
	String present_Month = String.valueOf(GregorianCalendar.getInstance().get(Calendar.MONTH)+1); 
	String present_Week = String.valueOf(GregorianCalendar.getInstance().get(Calendar.WEEK_OF_MONTH));
	String present_Date = String.valueOf(GregorianCalendar.getInstance().get(Calendar.DATE));
	
	if(present_Month.length() == 1){
		present_Month = "0" + present_Month; //01월,02월 ..... 09월
	}
	
	if(present_Date.length() == 1){
		present_Date = "0" + present_Date; //01일,02일 ..... 09일
	}
	
	//start_dt,close_dt,selected_year,selected_month 의 값에 받아오는 인자가 없을 경우 default로 현재 시간을 Setting
	String start_dt 		= CmmUtil.nvl(request.getParameter("start_dt"),present_Year + present_Month + present_Date);
	String close_dt 		= CmmUtil.nvl(request.getParameter("close_dt"),present_Year + present_Month + present_Date);
	
	String selected_year 	= CmmUtil.nvl(request.getParameter("selectYear"),present_Year);
	String selected_month 	= CmmUtil.nvl(request.getParameter("selectMonth"),present_Month);
	String selected_week 	= CmmUtil.nvl(request.getParameter("selectWeek"),present_Week);
	
	String send_values ="";
	if(statistics_type.equals("day")){ //일별통계조회 버튼 클릭시 넘어갈 인자
		send_values = "start_dt=" + start_dt + "&close_dt=" + close_dt + "&ent_id=" + ent_id + "&connGroup=" + connGroup + "&user_id=" + user_id;
	}else if(statistics_type.equals("week")){ //주별통계조회 버튼 클릭시 넘어갈 인자
		send_values = "yyyymm=" + selected_year + selected_month + "&week=" + selected_week + "&ent_id=" + ent_id + "&connGroup=" + connGroup + "&user_id=" + user_id;
	}else if(statistics_type.equals("month")){ //월별통계조회 버튼 클릭시 넘어갈 인자
		send_values = "yyyymm=" + selected_year + selected_month + "&ent_id=" + ent_id + "&connGroup=" + connGroup + "&user_id=" + user_id;
	}else if(statistics_type.equals("day_member")){ //일별(회원별)통계조회 버튼 클릭시 넘어갈 인자
		send_values = "start_dt=" + start_dt + "&close_dt=" + close_dt + "&ent_id=" + ent_id + "&connGroup=" + connGroup + "&user_id=" + user_id;
	}else if(statistics_type.equals("week_member")){ //주별(회원별)통계조회 버튼 클릭시 넘어갈 인자
		send_values = "yyyymm=" + selected_year + selected_month + "&week=" + selected_week + "&ent_id=" + ent_id + "&connGroup=" + connGroup + "&user_id=" + user_id;
	}else if(statistics_type.equals("month_member")){ //월별(회원별)통계조회 버튼 클릭시 넘어갈 인자
		send_values = "yyyymm=" + selected_year + selected_month + "&ent_id=" + ent_id + "&connGroup=" + connGroup + "&user_id=" + user_id;
	}
	
	System.out.println("statistics_typestatistics_type  " + statistics_type);
	System.out.println("statistics_typestatistics_type  " + statistics_url);
	
	//selectbox에서 사용될 변수
	int Year = GregorianCalendar.getInstance().get(Calendar.YEAR);
	int Week = GregorianCalendar.getInstance().get(Calendar.WEEK_OF_MONTH);
	String month1 = "";
	
	//OpenFlash 관련 start
	String base = request.getContextPath() + "/flash/";
	int width = 700;
	int height = 250;

	String dataurl 	="";
	String data_url ="";
	String url		="";

	String obj_id = "chart";
	
	//if(list != null && list.size() > 0){
	dataurl = request.getRequestURL().toString();
	data_url = "/jsp/"+statistics_url+".jsp?" + send_values;
	
	url = java.net.URLEncoder.encode(dataurl.replace(request.getContextPath() +"/jsp/com0301l_p01.jsp", 
		request.getContextPath() + data_url), "EUC-KR"); //openFlash로 넘길 URL 인코딩
	//}
	//OpenFlash 관련 End
	
	//타이틀
	String title = "일별";
	if(statistics_type.equals("day")){
		title = "일별";	
	}if(statistics_type.equals("week")){
		title = "주별";
	}if(statistics_type.equals("month")){
		title = "월별";
	}

%>
<script>
	function search_statistics(type,url){
		var frm = document.frm1;
		frm.statistics_url.value=url;
		frm.statistics_type.value=type;
		frm.target="_self";
		frm.method ="post";
		frm.action ="com0301l_p01.jsp";
		frm.submit();
	}
	
	function excel_down(type){
		var frm = document.frm1;
		frm.statistics_type.value=type;
		frm.target ="_blank";
		frm.method ="post";
		frm.action ="com0301l_p01_excel.jsp";
		frm.submit();
	}
</script>
<body>
<table width="992" border="0" cellpadding="0" cellspacing="0" align="center">
  <tr>
    <td>
    <!--top -->
    <jsp:include page="common/top_menu.jsp"></jsp:include> 
    <!-- //top -->
    <!-- contents area -->
  <table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="180" valign="top">
    	<jsp:include page="left/com0301l_p05.jsp"></jsp:include>
    </td>
    <td width="21" valign="top">&nbsp;</td>
    <td valign="top" style="margin:0 0 15px 0;">
    
<form name="frm1">
	<input type="hidden" name="statistics_type" value="">
	<input type="hidden" name="statistics_url" value="">
	<input type="hidden" name="connGroup" value="<%=connGroup %>">
	<input type="hidden" name=user_id value="<%=user_id %>">
	<input type="hidden" name=ent_id value="<%=ent_id %>">
	
    	 <table width="790px"  border="0" cellpadding="0" cellspacing="0">
            <tr>
                <td style="font-size:14px; color:#3b70a2; font-weight:bold; border-bottom:2px solid #c8c8c8; padding:0 0 5px 0;" align="left"><img src="/images/sub_icon1.jpg"  alt="" border="0">&nbsp;접속통계 - <%=title %></td>
            </tr>
        </table>
        <table width="790px"  border="0" cellpadding="0" cellspacing="0" style="margin:5px 0 0 0;">
        	<tr>
             <td align="left"><a href="javascript:excel_down('<%=statistics_type %>')"><img src="/images/btn_save_excel2.gif" align="absmiddle" /></a></td>
             <%if(statistics_type.equals("day")){ %>
             <td align="right">검색일자
               <input type="text" name="start_dt" class="textbox" required="required" hname="검색어" value="<%=start_dt %>"/>
				<script language=javascript>
					var basicCal = new calendar("FIELD:document.frm1.start_dt;FORMAT:2;DELIMITER:;");
					basicCal.writeCalendar();
				</script>
               ~
               <input type="text" name="close_dt" class="textbox" required="required" hname="검색어" value="<%=close_dt %>"/>
				<script language=javascript>
					var basicCal = new calendar("FIELD:document.frm1.close_dt;FORMAT:2;DELIMITER:;");
					basicCal.writeCalendar();
				</script>
               <a href="javascript:search_statistics('day','com0301l_p02')"><img src="/images/bt_search2.gif" align="absmiddle" /></a>             
             </td>              
              <%}else if(statistics_type.equals("week")){ %>
			  <td align="right"> 
			  	 <select name="selectYear">
			  	 	<%for(int i=0; i<3; i++){ %>
                    <option value="<%=Year-i%>" <%if((String.valueOf(Year-i)).equals(selected_year)){%> selected <%}%> ><%=Year-i%></option>
                    <%} %>
                  </select>
					년
                  <select name="selectMonth">
			  	 	<%
			  	 	
			  	 	for(int i=0; i<12; i++){
			  	 		month1 = String.valueOf(i+1);
			  	 		if(month1.length() == 1){
			  	 			month1 = "0" + month1;
			  	 		}
			  	 	%>
                    <option value="<%=month1%>" <%if(selected_month.equals(month1)){%> selected <%}%> ><%=month1%></option>
                    <%} %>
                  </select>
					월
                  <select name="selectWeek">
			  	 	<%for(int i=0; i<6; i++){ %>
                    <option value="<%=i+1%>" <%if(selected_week.equals(String.valueOf(i+1))){%> selected <%}%>><%=i+1%></option>
                    <%} %>
                  </select>
					주
					&nbsp;
                 <a href="javascript:search_statistics('week','com0301l_p03')">
                 	<image src="/images/bt_search2.gif" align="absmiddle" />
                 </a>             
              </td>
              <%}else if(statistics_type.equals("month")){ %>
			  <td align="right"> 
			  	 <select name="selectYear">
			  	 	<%for(int i=0; i<3; i++){ %>
                    <option value="<%=Year-i%>" <%if((String.valueOf(Year-i)).equals(selected_year)){%> selected <%}%> ><%=Year-i%></option>
                    <%} %>
                  </select>
					년
                  <select name="selectMonth">
			  	 	<%
			  	 	for(int i=0; i<12; i++){
			  	 		month1 = String.valueOf(i+1);
			  	 		if(month1.length() == 1){
			  	 			month1 = "0" + month1;
			  	 		}
			  	 	%>
                    <option value="<%=month1%>" <%if(selected_month.equals(month1)){%> selected <%}%> ><%=month1%></option>
                    <%} %>
                  </select>
					월
					&nbsp;
				 <a href="javascript:search_statistics('month','com0301l_p04')">
                 	<image src="/images/bt_search2.gif" align="absmiddle" />
                 </a>              
              </td>
              <%}else if(statistics_type.equals("day_member")){ %>
             <td align="right">검색일자
               <input type="text" name="start_dt" class="textbox" required="required" hname="검색어" value="<%=start_dt %>"/>
				<script language=javascript>
					var basicCal = new calendar("FIELD:document.frm1.start_dt;FORMAT:2;DELIMITER:;");
					basicCal.writeCalendar();
				</script>
               ~
               <input type="text" name="close_dt" class="textbox" required="required" hname="검색어" value="<%=close_dt %>"/>
				<script language=javascript>
					var basicCal = new calendar("FIELD:document.frm1.close_dt;FORMAT:2;DELIMITER:;");
					basicCal.writeCalendar();
				</script>
               <a href="javascript:search_statistics('day_member','com0303l_p02')"><img src="/images/bt_search2.gif" align="absmiddle" /></a>             
             </td> 
			  <%}else if(statistics_type.equals("week_member")){ %>
			  <td align="right"> 
			  	 <select name="selectYear">
			  	 	<%for(int i=0; i<3; i++){ %>
                    <option value="<%=Year-i%>" <%if((String.valueOf(Year-i)).equals(selected_year)){%> selected <%}%> ><%=Year-i%></option>
                    <%} %>
                  </select>
					년
                  <select name="selectMonth">
			  	 	<%
			  	 	
			  	 	for(int i=0; i<12; i++){
			  	 		month1 = String.valueOf(i+1);
			  	 		if(month1.length() == 1){
			  	 			month1 = "0" + month1;
			  	 		}
			  	 	%>
                    <option value="<%=month1%>" <%if(selected_month.equals(month1)){%> selected <%}%> ><%=month1%></option>
                    <%} %>
                  </select>
					월
                  <select name="selectWeek">
			  	 	<%for(int i=0; i<6; i++){ %>
                    <option value="<%=i+1%>" <%if(selected_week.equals(String.valueOf(i+1))){%> selected <%}%>><%=i+1%></option>
                    <%} %>
                  </select>
					주
					&nbsp;
                 <a href="javascript:search_statistics('week_member','com0303l_p03')">
                 	<image src="/images/bt_search2.gif" align="absmiddle" />
                 </a>             
              </td>
              <%}else if(statistics_type.equals("month_member")){ %>
			  <td align="right"> 
			  	 <select name="selectYear">
			  	 	<%for(int i=0; i<3; i++){ %>
                    <option value="<%=Year-i%>" <%if((String.valueOf(Year-i)).equals(selected_year)){%> selected <%}%> ><%=Year-i%></option>
                    <%} %>
                  </select>
					년
                  <select name="selectMonth">
			  	 	<%
			  	 	for(int i=0; i<12; i++){
			  	 		month1 = String.valueOf(i+1);
			  	 		if(month1.length() == 1){
			  	 			month1 = "0" + month1;
			  	 		}
			  	 	%>
                    <option value="<%=month1%>" <%if(selected_month.equals(month1)){%> selected <%}%> ><%=month1%></option>
                    <%} %>
                  </select>
					월
					&nbsp;
				 <a href="javascript:search_statistics('month_member','com0303l_p04')">
                 	<image src="/images/bt_search2.gif" align="absmiddle" />
                 </a>              
              </td>
              <%} %>
			</tr>
        </table>
</form>
         <table width="100%" border="0" cellpadding="0" cellspacing="0"  style="margin:5px 0 10px 0; padding:10px 0 10px 0; border:1px solid #cfcfcf;">
           <tr>
             <td align="center"> 
             
<!-- 그래프 -->
<div class="score-subject-div"> 
	<div class="subject-value">
		<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" 
			codebase="<%= request.getProtocol() %>://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"
			width="<%=width %>" height="<%=height %>" id="ie_<%=obj_id %>" align="middle">
				<param name="allowScriptAccess" value="sameDomain" />
				<param name="movie" value="<%=base%>open-flash-chart.swf?width=<%=width%>&height=<%=height%>&data=<%=url%>" />
				<param name="wmode" value="transparent" />
				<param name="quality" value="high" />
				<param name="bgcolor" value="#FFFFFF" />
				<embed src="<%=base%>open-flash-chart.swf?data=<%=url%>" quality="high" bgcolor="#FFFFFF" width="<%=width%>" height="<%=height%>" name="<%=obj_id%>" align="middle" allowScriptAccess="sameDomain"
					type="application/x-shockwave-flash" pluginspage="<%=request.getProtocol()%>://www.macromedia.com/go/getflashplayer" id="<%=obj_id%>"/>
		</object>
	</div>
</div>
<!-- //그래프 -->   
    
     
              </td>

           </tr>
         </table></td>
  </tr>
</table>

<jsp:include page="common/footer.jsp"></jsp:include>
	</td>
  </tr>
</table>
</body>
</html>
